home *** CD-ROM | disk | FTP | other *** search
/ 8bitfiles.net/archives / archives.tar / archives / compuserve-file-archive / 03 Demos and Info / BPLUS.DOC < prev    next >
Encoding:
Text File  |  2019-04-13  |  70.4 KB  |  2,079 lines

  1.  
  2.  
  3.      
  4.      
  5.      
  6.      
  7.      
  8.      
  9.      
  10.      
  11.      
  12.      
  13.      
  14.      
  15.      
  16.      
  17.      
  18.      
  19.      
  20.      
  21.                            The CompuServe B Plus Protocol
  22.      
  23.                                 May 16, 1988  2:10 PM
  24.      
  25.                                          by
  26.      
  27.                                     Russ Ranshaw
  28.  
  29.  
  30.  
  31.                                   TABLE OF CONTENTS
  32.  
  33.  
  34.  A. Introduction.
  35.  B. Notation.
  36.  C. B Plus Packets.
  37.     1. B Plus Packet Structure.
  38.     2. Quoting of characters.
  39.     3. Check Value.
  40.     4. B Plus Packet Types.
  41.        a) Packet Type `+':  Transport Parameters.
  42.        b) Packet Type `T':  File Transfer.
  43.        c) Packet Type `N':  Data.
  44.        d) Packet Type `F':  Failure.
  45.        e) Optional `T' Packets.
  46.           1) Packet `Tr' : Download Resume.
  47.           2) Packet `Tu' : Upload Resume.
  48.           3) Packet `Tf' : Failed CRC.
  49.           4) Packet `TI' : File Information.
  50.  D. B Plus Control Sequences.
  51.     1. Enquire.
  52.     2. Positive Acknowledge.
  53.     3. Wait.
  54.     4. Negative Acknowledge.
  55.     5. Panic Abort.
  56.  E. Negotiation of Transport Parameters.
  57.  F. Terminal Program States.
  58.  G. Wait for Acknowledge.
  59.  H. Packet Send Ahead
  60.  I. Implementation Considerations
  61.     1. Time-Out
  62.     2. Packet Size.
  63.     3. Controlling Excessive Retransmissions.
  64.  J. B Plus Transport Layer.
  65.  K. Initiation of a B Plus Session.
  66.  L. Supporting the Various B Protocol Versions
  67.  M. Check Value Calculation.
  68.     1. Standard B Protocol Checksum.
  69.     2. XMODEM-Style CRC-16.
  70.  N. Interrogation.
  71.  
  72.  
  73.  
  74.  
  75.       A. Introduction.
  76.      
  77.          The CompuServe B protocol was developed in 1981 to provide
  78.          support for a special purpose Vidtex terminal manufactured
  79.          by the Tandy Corporation.  It was the outgrowth of a
  80.          proposed Bi-Sync oriented protocol, but with a different
  81.          packet structure and provision for more than even and odd
  82.          packets.  The file transfer capability was added in 1982 to
  83.          replace the CompuServe A protocol with a more robust
  84.          protocol which was in keeping with the over-all B Protocol
  85.          design.
  86.      
  87.          Some of the underlying assumptions made in designing the B
  88.          Protocol were due to the capabilities of personal computers
  89.          which were available at the time.  Such machines were
  90.          generally limited in the amount of available memory, 64
  91.          kilobytes being a large capacity.  Other factors, such as
  92.          the lack of a true UART for data communications, resulted in
  93.          the send/wait nature of the protocol where only a single
  94.          protocol packet at a time was sent.
  95.      
  96.          The explosive growth of the Personal Computer industry has
  97.          given us a plethora of machines, most of which have far
  98.          exceeded the early limitations of memory and communication
  99.          ability.  This growth has been accompanied by a multitude of
  100.          file transfer protocols, such as XMODEM, KERMIT, and ZMODEM.
  101.          CompuServe, realizing the need for enhancement, has
  102.          developed the B Plus Protocol to meet the increasing demands
  103.          being made upon its communication network and host
  104.          computers, and to provide added utility for its large family
  105.          of users.
  106.      
  107.          As the name implies, B Plus is an extension of the B
  108.          Protocol.  In particular:
  109.               o  Ability to send multiple packets without waiting for
  110.                  individual acknowledgements.
  111.               o  Larger data packets (up to 1k at present).
  112.               o  Optional use of modified XMODEM CRC-16 check method.
  113.               o  Extensions to the standard control character
  114.                  quoting.
  115.               o  Provision of a mechanism to exchange transport and
  116.                  application parameters.
  117.      
  118.      
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125.  
  126.  
  127.  
  128.  
  129.  
  130.                                         2
  131.  
  132.  
  133.  
  134.       B. Notation.
  135.      
  136.          Throughout the remainder of this document the following
  137.          notational conventions will be used:
  138.      
  139.               o  Protocol elements are enclosed within angle
  140.                  brackets.  For example:
  141.                         <DLE>
  142.                  specifies the ASCII code for Data Link Escape.
  143.      
  144.               o  The C-language notation for hexadecimal values will
  145.                  be used.  Thus, the <DLE> character will also be
  146.                  shown as 0x10.
  147.      
  148.          Two entities (computers) are involved in a B Plus session.
  149.          The term "Initiator" is used to refer to the entity which
  150.          initiates the session.  "Responder" refers to the entity
  151.          which receives the initiate command.
  152.      
  153.          CompuServe host computers will always be the Initiator in
  154.          any communication established with them.
  155.      
  156.          For further information regarding Host support, see Section
  157.          "K. Initiation of a B Plus Session."
  158.      
  159.      
  160.  
  161.  
  162.  
  163.  
  164.  
  165.  
  166.  
  167.  
  168.  
  169.  
  170.  
  171.  
  172.  
  173.  
  174.  
  175.  
  176.  
  177.  
  178.  
  179.  
  180.  
  181.  
  182.  
  183.  
  184.  
  185.  
  186.  
  187.  
  188.  
  189.                                         3
  190.  
  191.  
  192.  
  193.       C. B Plus Packets.
  194.      
  195.          1. B Plus Packet Structure.
  196.      
  197.             B Plus Protocol packets consist of five parts as follows:
  198.      
  199.                  o  Lead-in       <DLE> <B>
  200.                  o  Sequence      <0x30 thru 0x39>
  201.                  o  Type          <Single byte>
  202.                  o  Body          <zero to 1024 data bytes>
  203.                  o  Trailer       <ETX> <Check Value>
  204.      
  205.             The Sequence is incremented by one for each successfully
  206.             transmitted packet.  It wraps from 0x39 back to 0x30.  (Note
  207.             that 0x30 is the ASCII character 0 and 0x39 is 9.)
  208.      
  209.             The Sequence, Type, all Body data, and <ETX> are included in
  210.             the Check Value.  Note that <Body> and <Check Value> are
  211.             Quoted, and that the Check Value is computed on the actual
  212.             data bytes rather than their quoted replacements (the
  213.             quoting <DLE> is not included).  Hence, if the character
  214.             0x13 is to be sent, it is sent as <DLE> <S> but the value
  215.             0x13 is included in the Check Value.
  216.      
  217.             If Standard Checksum is used, <Check Value> consists of a
  218.             quoted byte.
  219.      
  220.             If the XMODEM CRC-16 is used, <Check Value) is transmitted
  221.             as two quoted bytes with the most significant byte appearing
  222.             first.  By performing the CRC calculation on the XMODEM
  223.             CRC-16 value,  the result will be 0x0000 if no errors
  224.             occured.
  225.      
  226.             A sample B Plus packet, sent using the Standard Checksum, is
  227.             as follows:
  228.      
  229.                 <DLE>  B    7    T    D    A    S    .    C  <ETX> 0x2A
  230.                 0x10 0x42 0x37 0x54 0x44 0x41 0x53 0x2E 0x43 0x03  0x2A
  231.      
  232.             where
  233.                      Lead-in   =    <DLE> B
  234.                      Sequence  =    7
  235.                      Type      =    T
  236.                      Body      =    DAS.C
  237.                      Trailer   =    <ETX> 0x2A
  238.      
  239.             If the packet was sent using the XMODEM CRC-16 option, the
  240.             Check Value would be 0x57 0xFF instead of 0x2A.
  241.      
  242.  
  243.  
  244.  
  245.  
  246.  
  247.  
  248.                                         4
  249.  
  250.  
  251.  
  252.          2. Quoting of characters.
  253.      
  254.             The B Plus Protocol quotes certain ASCII control characters.
  255.             The default set of quoted characters is:
  256.      
  257.                  o  <ETX>  0x03
  258.                  o  <ENQ>  0x05
  259.                  o  <DLE>  0x10
  260.                  o  <DC1>  0x11
  261.                  o  <DC3>  0x13
  262.                  o  <NAK>  0x15
  263.      
  264.             The quoting mechanism uses the <DLE> character to prefix the
  265.             quoted character.  The quoted character with 0x40 added
  266.             follows the <DLE>.  For example, <ETX> is quoted as:
  267.      
  268.                  <DLE>  C
  269.                  0x10 0x43
  270.      
  271.             B Plus also provides a means for the Initiator and Responder
  272.             to establish a different set of quoted characters.  This set
  273.             may consist of any or all characters in the ranges 0x00 thru
  274.             0x1f and 0x80 thru 0x9f.
  275.      
  276.             Quoted characters in the 0x80 thru 0x9f range are sent as:
  277.      
  278.                 <DLE> ((char and 0x1f) + 0x60)
  279.      
  280.             Hence, 0x93 is quoted as:
  281.      
  282.                 <DLE>  s
  283.                 0x10  0x73
  284.      
  285.             When receiving protocol data, the program should be capable
  286.             of decoding any quoted character, regardless of the set of
  287.             quoted characters in use.  This must be accomplished as
  288.             follows:
  289.      
  290.                 Get a character.
  291.                 If the character is <DLE>
  292.                 then
  293.                      Get next character.
  294.                      If character is less than 0x60
  295.                      then
  296.                           character = character and 0x1f
  297.                      else
  298.                           character = (character and 0x1f) + 0x80
  299.      
  300.  
  301.  
  302.  
  303.  
  304.  
  305.  
  306.  
  307.                                         5
  308.  
  309.  
  310.  
  311.          3. Check Value.
  312.      
  313.             Each B Plus packet contains a Check Value to allow detection
  314.             of transmission errors.  The B Plus Protocol supports two
  315.             Check Value methods as follows:
  316.      
  317.             a) Standard B Protocol Checksum.
  318.      
  319.                The Standard Checksum is calculated as follows:
  320.      
  321.                     o  The checksum is initialized to zero.
  322.                     o  For each byte that is to be checksummed:
  323.                          -  The old checksum is rotated left 1, with the
  324.                             old bit 7 becoming bit 0 in the rotated value.
  325.                          -  The new byte is added to the rotated checksum.
  326.                          -  If addition of the new byte causes a carry,
  327.                             then one is added to the new value.
  328.      
  329.      
  330.             b) XMODEM-Style CRC-16.
  331.      
  332.                B Plus implementations may optionally specify that the
  333.                defacto standard XMODEM CRC-16 be used as a check value.
  334.                The only departure is that the CRC-16 value is initialized
  335.                to 0xffff instead of zero.
  336.      
  337.      
  338.             Sample C code for calculating these Check Values is presented in
  339.             Section "H. Check Value Calculation."
  340.      
  341.      
  342.  
  343.  
  344.  
  345.  
  346.  
  347.  
  348.  
  349.  
  350.  
  351.  
  352.  
  353.  
  354.  
  355.  
  356.  
  357.  
  358.  
  359.  
  360.  
  361.  
  362.  
  363.  
  364.  
  365.  
  366.                                         6
  367.  
  368.  
  369.  
  370.          4. B Plus Packet Types.
  371.      
  372.             The following Packet Types are the minimum required to
  373.             support the B Plus Protocol:
  374.      
  375.                 o  `+':  Transport Parameters
  376.                 o  `T':  File Transfer
  377.                 o  `N':  Data
  378.                 o  `F':  Failure
  379.      
  380.             a) Packet Type `+':  Transport Parameters.
  381.      
  382.                This is the B Plus Transport Parameters Packet.  It
  383.                describes an entity`s Transport capabilities.  The Transport
  384.                Parameters Packet is always sent with all characters in the
  385.                ranges 0x00 thru 0x1f and 0x80 thru 0x9f quoted, and using
  386.                the Standard Checksum.
  387.      
  388.                The Body of the <+> packet is a series of bytes as follows:
  389.      
  390.                     WS WR BS CM DQ TL Q1 Q2 Q3 Q4 Q5 Q6 Q7 Q8 DR UR FI
  391.      
  392.                where:
  393.      
  394.                     WS = Window Send.  0x00 implies that a single packet at
  395.                          a time can be sent, 0x01 two packets.  The default
  396.                          is 0x00.
  397.      
  398.                     WR = Window Receive.  0x00 implies that the entity
  399.                          cannot receive other than a single packet at a
  400.                          time (that is, requests the other entity to use
  401.                          WS = 0x00);  0x01 implies two packets.  The
  402.                          default is 0x00.
  403.      
  404.                     BS = Block Size.  This specifies the maximum size of
  405.                          the <Body> divided by 128.  Thus 0x04 represents
  406.                          512 bytes and 0x08 is 1024 bytes.  The value 0x00
  407.                          implies the default size of 512 bytes.
  408.      
  409.                     CM = Check Method.  0x00 is standard checksum; 0x01 is
  410.                          XMODEM CRC-16 initialized to 0xffff.  Note that
  411.                          CompuServe recommends the use of CRC-16 instead
  412.                          of the standard checksum due to its superior error
  413.                          detection capability.  The default is Standard
  414.                          Checksum, 0x00.
  415.      
  416.  
  417.  
  418.  
  419.  
  420.  
  421.  
  422.  
  423.  
  424.  
  425.                                         7
  426.  
  427.  
  428.  
  429.                     DQ = Data Quoting Level.  This parameter is part of an
  430.                          interim version of the B Plus Protocol.  It has
  431.                          been superceeded by the eight byte Quoting Set in
  432.                          Parameters Q1 thru Q8 (below).  For historical
  433.                          purposes, the Quoting Levels are:
  434.      
  435.                              0x00:  0x00 0x03 0x05 0x10 0x11 0x13 0x15
  436.                              0x01:  0x03 0x05 0x10 0x11 0x13 0x15
  437.                              0x02:  0x03 0x05 0x10 0x11 0x13 0x15 0x91 0x93
  438.                              0x03:  0x00 thru 0x1f and 0x80 thru 0x9f
  439.      
  440.                          If a Parameters packet contains Q1-Q8, the DQ must
  441.                          be ignored and the quoting set established from
  442.                          Q1-Q8.  If Q1-Q8 are absent, the above definitions
  443.                          must be used.
  444.                         
  445.                     TL = Transport Layer.  The Initiator sets the TL
  446.                          parameter to 0x01 when it is running an         
  447.                          application that must run under the Transport
  448.                          Layer.  If the Responder`s half of the application
  449.                          also utilizes the Transport Layer, it must also
  450.                          set the TL parameter to 0x01.  The default value
  451.                          is 0x00.  More information is in Section "J. B
  452.                          Plus Transport Layer."
  453.      
  454.                     Q1-Q4 = A mask indicating which characters in the range
  455.                          0x00 thru 0x1f the entity wants quoted.  The    
  456.                          mapping of bits to characters is:
  457.      
  458.                            Bit:   7    6    5    4    3    2    1    0
  459.                            ----- ---- ---- ---- ---- ---- ---- ---- ----
  460.                              Q1: 0x00 0x01 0x02 0x03 0x04 0x05 0x06 0x07
  461.                              Q2: 0x08 0x09 0x0a 0x0b 0x0c 0x0d 0x0e 0x0f
  462.                              Q3: 0x10 0x11 0x12 0x13 0x14 0x15 0x16 0x17
  463.                              Q4: 0x18 0x19 0x1a 0x1b 0x1c 0x1d 0x1e 0x1f
  464.                         
  465.                          CompuServe Hosts currently use:
  466.      
  467.                              0x14 0x00 0xd4 0x00
  468.      
  469.                     Q5-Q8  Same as Q1-Q4 for the range 0x80 thru 0x9f.
  470.                            CompuServe Hosts currently use:
  471.      
  472.                              0x00 0x00 0x00 0x00
  473.      
  474.                     DR     Download Resume.
  475.                                  0x00 : Download Resume not supported
  476.                                  0x01 : Supports `Tr' Packet
  477.                                  0x02 : Supports `Tr' and `Tf' Packets
  478.      
  479.  
  480.  
  481.  
  482.  
  483.  
  484.                                         8
  485.  
  486.  
  487.  
  488.                     UR     Upload Resume.
  489.                                  0x00 : Upload Resume not supported
  490.                                  0x01 : Supports `Tu' Packet
  491.                                  0x02 : Supports `Tu' and `Tf' Packets
  492.      
  493.                     FI     File Information.  This parameter specifies the
  494.                            level of extended file handling supported.
  495.      
  496.                                  0x00 = No extended file handling
  497.                                  0x01 = `TI' (File Information) Packet
  498.                 
  499.                These are the currently defined Transport Layer Parameters.
  500.                CompuServe reserves the right to define additional
  501.                parameters at any time.  Programs should be capable of
  502.                accepting any number of parameters.  Received parameters
  503.                beyond the known ones must be ignored. If fewer Transport
  504.                Parameters are received than the entity understands, then
  505.                any beyond the last received parameter must be treated as if
  506.                it was provided as 0x00, which must be its default value.
  507.      
  508.                See Section "E.  Negotiation of Transport Parameters" for
  509.                details on deciding what level of capabilities each entity
  510.                is to use.
  511.      
  512.  
  513.  
  514.  
  515.  
  516.  
  517.  
  518.  
  519.  
  520.  
  521.  
  522.  
  523.  
  524.  
  525.  
  526.  
  527.  
  528.  
  529.  
  530.  
  531.  
  532.  
  533.  
  534.  
  535.  
  536.  
  537.  
  538.  
  539.  
  540.  
  541.  
  542.  
  543.                                         9
  544.  
  545.  
  546.  
  547.             b) Packet Type `T':  File Transfer.
  548.      
  549.                The File Transfer Packet consists of three fields as
  550.                follows:
  551.      
  552.                     <Direction> <Data type> <File name>
  553.      
  554.                1) Function.
  555.                        `D' = Download (Initiator -> Responder)
  556.                        `U' = Upload (Responder -> Initiator)
  557.                        `C' = Close.  End of Upload or Download
  558.      
  559.                   (Note:  Additional "T" packets are defined later.)
  560.      
  561.                2) Data type.
  562.                        `A' = 7-bit ASCII data.  (Allows for End of Line       
  563.                                                  conversion.)
  564.                        `B' = 8-bit Binary data.
  565.                        `I' = Image data.  (This is hardware specific data and
  566.                              usually consists of some embedded header which
  567.                              describes the remainder of the file.  It is
  568.                              always 8-bit binary data.)
  569.      
  570.                3) File Name.
  571.      
  572.                   This field is variable length and specifies the name of the
  573.                   file to be transfered.
  574.      
  575.      
  576.                A sample File Transfer packet using CRC Check Method is:
  577.      
  578.                   <DLE>  B    7    T    D    A    S    .    C  <ETX> 0x57 0xff
  579.      
  580.                    0x10 0x42 0x37 0x54 0x44 0x41 0x53 0x2e 0x43 0x03 0x57 0xff
  581.      
  582.                which specifies:
  583.                    o    `T':  File Transfer
  584.                    o    `D':  Download to the Responder
  585.                    o    `A':  This is an ASCII file
  586.                    o  `S.C':  The file name
  587.      
  588.                Note that there are no guidelines as to what the Responder
  589.                is to do with the File Transfer packet.  In particular, the
  590.                implementor is free to locally verify the request, permit
  591.                the file name to be changed, etc.
  592.      
  593.                If the Responder does not wish to comply with the request
  594.                made in the File Transfer packet, a Failure Packet must be
  595.                returned to the Initiator.
  596.      
  597.  
  598.  
  599.  
  600.  
  601.  
  602.                                         10
  603.  
  604.  
  605.  
  606.             c) Packet Type `N':  Data.
  607.      
  608.                This is a data packet.  The data being transferred is broken
  609.                up into a series of <N> packets.  There may be zero to the
  610.                negotiated data block size.  A count of zero does not imply
  611.                end of file.
  612.      
  613.             d) Packet Type `F':  Failure.
  614.      
  615.                This is the general Failure Packet.  A Failure Packet may be
  616.                sent at any time; the value of the <Sequence> field is
  617.                ignored.  The first character of the <Body> indicates the
  618.                general nature of the failure, and the remainder may be a
  619.                printable ASCII message further describing the condition.
  620.                The following standard failures must be supported:
  621.      
  622.                     `A':  Abort.  Usually sent if the user requests that the
  623.                           terminal program cease tranferring data.
  624.      
  625.                     `C':  Capacity failure.  Out of memory or disk.
  626.      
  627.                     `E':  Processing error.  Any error other than described
  628.                           by another Failure Packet.
  629.      
  630.                     `I':  I/O error occured.
  631.      
  632.                     `M':  File requested for Uploading is Missing (not 
  633.                           found).
  634.      
  635.                     `N':  Unimplemented Packet Type was received.
  636.      
  637.                     `S':  Protocol Sequence Number failure.
  638.      
  639.                     `r`:  Transfer Resume failure.
  640.      
  641.                When a Failure Packet is received, it must be acknowledged and
  642.                the transfer aborted.  Similarly, when a Failure Packet is sent,
  643.                the sending entity must wait for the acknowledge to arrive.  In
  644.                addition, the entity which sends the Failure Packet must ignore
  645.                all other packets while waiting for the acknowledgement to
  646.                arrive.  Once the Failure Packet is successfully transfered,
  647.                both entities are expected to leave protocol mode.
  648.      
  649.  
  650.  
  651.  
  652.  
  653.  
  654.  
  655.  
  656.  
  657.  
  658.  
  659.  
  660.  
  661.                                         11
  662.  
  663.  
  664.  
  665.             e) Optional `T' Packets.
  666.      
  667.                Several "T" Packets may optionally be supported.  The
  668.                support for these packets is specified by the DR, UR, and FI
  669.                Transport Parameters.
  670.      
  671.                1) Packet `Tr' : Download Resume.
  672.      
  673.                   When the Responder receives the "TD" (Download Request)
  674.                   packet and the specified file already exits, it may attempt
  675.                   to resume the download which was aborted during a prior
  676.                   session.  In order to do this, both entities must specify
  677.                   Transport Parameter DR > 0x00.  If the Responder attempts
  678.                   the resumption, a `Tr' Packet is returned to the Initiator
  679.                   as follows:
  680.      
  681.                       <DLE> B <Sequence> T r <Length> <CRC-16> <ETX> <Trailer>
  682.      
  683.                   where:
  684.      
  685.                       <Length> = current number of bytes in Responder's
  686.                                  existing file.
  687.      
  688.                       <CRC-16> = XMODEM CRC-16, initialized to 0xffff, of all
  689.                                existing data in Responder's file.
  690.      
  691.                   Both <Length> and <CRC-16> are transmitted as an ASCII
  692.                   decimal string and are both followed by at least a single
  693.                   space.
  694.      
  695.                   The Initiator will perform the same CRC-16 calculation over
  696.                   <Length> bytes and compare the resulting CRC-16 values.  If
  697.                   the calculated and `Tr' values agree, downloading continues
  698.                   with `N` Packets and Responder appends the data to the
  699.                   existing file.  If the files match exactly, a `TC' (Transfer
  700.                   Close) packet is sent.
  701.      
  702.                   If the CRC-16 values do not match, or the Initiator's file
  703.                   be shorter than <Length> bytes, the Initiator's response
  704.                   depends on the value of the DR Transport Parameter:
  705.      
  706.                           0x01 - A `Fr' (Failed Resume) Packet is sent
  707.                           0x02 - A `Tf' (CRC Failed) Packet is sent
  708.      
  709.                   Some operating environments complicate Download Recovery.
  710.                   Since the Initiator has no knowledge of any data
  711.                   transformations, such as  Carriage Return and Line Feed
  712.                   mappings, the Responder must take any such transformations
  713.                   into consideration when calculating <length> and <CRC-16>.
  714.                   Under some environments, it is probably simpler to maintain
  715.                   this information during the download and preserve it in a
  716.                   file (Apple Macintosh (TM) for example.)
  717.      
  718.      
  719.  
  720.                                         12
  721.  
  722.  
  723.  
  724.                2) Packet `Tu' : Upload Resume.
  725.      
  726.                   The Upload Resume Packet is sent by the Initiator if both
  727.                   entities have the Transport Parameter UR > 0x00, the target
  728.                   file already exists on the Initiator, and the application
  729.                   software has decided to attempt an upload resumption.  It is
  730.                   essentially a `TU' Packet with <length> and <CRC-16> fields.
  731.                   It is constructed as follows:
  732.      
  733.                       <Lead-in> <Sequence > T u <Data Type> <Length> <CRC-16>
  734.                            <File Name> <Trailer>
  735.      
  736.                   where:
  737.                       <Data Type> = same as for the `TU' Packet
  738.                       <Length>    = number of bytes in existing file on
  739.                                     Initiator
  740.                       <CRC-16>    = XMODEM CRC-16, initialized to 0xffff, of
  741.                                     all <Length> bytes
  742.                       <File Name> = same as for the `TU' Packet
  743.      
  744.                   The Responder opens <File Name> and calculates the CRC-16
  745.                   for <Length> bytes.  If the resulting CRC-16 agrees with
  746.                   <CRC-16> from the `Tu' Packet, it continues by sending `N'
  747.                   Packets.
  748.      
  749.                   If the CRC-16 values do not match, the action depends on the
  750.                   value of Transport Parameter UR:
  751.      
  752.                           0x01 - A `Fr' (Failed Resume) Packet is sent
  753.                           0x02 - A `Tf' (Failed CRC) Packet is sent
  754.      
  755.                   The same operating environment considerations mentioned
  756.                   under the `Tr' Packet apply here.
  757.      
  758.  
  759.  
  760.  
  761.  
  762.  
  763.  
  764.  
  765.  
  766.  
  767.  
  768.  
  769.  
  770.  
  771.  
  772.  
  773.  
  774.  
  775.  
  776.  
  777.  
  778.  
  779.                                         13
  780.  
  781.  
  782.  
  783.                3) Packet `Tf' : Failed CRC.
  784.      
  785.                   The `Tf' packet is sent when a Resume request fails due to
  786.                   CRC failure.  It will be sent only if the Responder and
  787.                   Initiator both specify Transport Parameter DR > 1.  It
  788.                   implies that the transfer is to continue from the beginning
  789.                   of the file.
  790.      
  791.                   Sample packet exchanges for transfer resumption:
  792.      
  793.                           Initiator           Responder      Comments
  794.                           ---------           ---------      -----------------
  795.                   DR = 0x01 or 0x02:
  796.                           TD --------------->                Download Request
  797.                              <--------------- Tr             Resume Download
  798.                           N  --------------->                CRC matched
  799.                                  ...
  800.                           TC --------------->                End of transfer
  801.      
  802.                   DR = 0x01:
  803.                           TD --------------->                Download Request
  804.                              <--------------- Tr             Resume Download
  805.                           Fr --------------->                Resume failed
  806.      
  807.                   DR = 0x02:
  808.                           TD --------------->                Download Request
  809.                              <--------------- Tr             Resume Download
  810.                           Tf --------------->                CRC mismatched
  811.                              <--------------- ACK            Transfer entire
  812.                           N  --------------->                Data
  813.                                 ...
  814.                           TC --------------->                End of transfer
  815.      
  816.                   UR = 0x01 or 0x02:
  817.                           Tu --------------->                Upload Resume
  818.                              <--------------  N              CRC Matched
  819.                                 ...
  820.                              <--------------  TC             End of transfer
  821.      
  822.                   UR = 0x01:
  823.                           Tu --------------->                Upload Resume
  824.                              <--------------- Fr             CRC mismatch
  825.      
  826.                   UR = 0x02:
  827.                           Tu --------------->                Upload Resume
  828.                              <--------------- Tf             CRC mismatch
  829.                           ACK--------------->                Transfer entire
  830.                                                              FIle
  831.                              <--------------- N              Data
  832.                                 ...
  833.                              <--------------- TC             End of transfer
  834.      
  835.      
  836.  
  837.  
  838.                                         14
  839.  
  840.  
  841.  
  842.                4) Packet `TI' : File Information.
  843.      
  844.                   The `TI' Packet is transmitted by the File Sender, provided
  845.                   that both entities have their Transport Parameter FI > 0x00.
  846.                   It is used to convey specific data concerning the file as it
  847.                   exists on the Sending entity.  The format of the `TI' Packet
  848.                   is as follows:
  849.      
  850.                       <Lead-in> <Sequence> T I <data type> <compression >
  851.                           <file length> <creation date> <creation time>
  852.                           <modification date> <modification time>
  853.                           <true name length> <true name> <Trailer>
  854.      
  855.                   where:
  856.                       <data type> :  A = ASCII, B = Binary.
  857.      
  858.                       <compression> :  Specifies how the file is compressed
  859.                                        during transmission (has nothing to do
  860.                                        with the content of the file).
  861.                                          0x00 = not compressed
  862.                                                 (other values reserved for
  863.                                                  future use by CompuServe)
  864.      
  865.                       <file length> :  Current length of the file being sent.
  866.                                        (Actual number of file data bytes being
  867.                                        sent, not the number of compressed
  868.                                        bytes).  This value is passed for display
  869.                                        display or media check only.  
  870.                                          
  871.                       <zone> :           Minutes offset from UCT of Sender.
  872.      
  873.                       <creation date> :  Date the file was created.
  874.                                          ASCII decimal string, yyyymmdd
  875.      
  876.                       <creation time> :  Time of day the file was created.
  877.                                          ASCII decimal string, seconds
  878.                                          since midnight.
  879.      
  880.                       <modification date> :  Date the file was last modified.
  881.                                          Same format as <creation date>.
  882.                                          (`0' if unknown)
  883.      
  884.                       <modification time> :  Time of day the file was last
  885.                                          modified.  Same format as
  886.                                          <creation time>.  (`0' if unknown)
  887.                        
  888.                       <true name length> :  Number of bytes in <true name>.
  889.                                             (This is a single binary byte.)
  890.      
  891.                       <true name> : The actual file name with any device,
  892.                                     directory, or other ancillary information
  893.                                     removed.
  894.      
  895.                   It is not necessary that all fields be transmitted.
  896.  
  897.                                         15
  898.  
  899.  
  900.  
  901.      
  902.                   A sample TI packet (file information only) is:
  903.      
  904.                      "A?55387 300 19880422 52480 0 0 ?BPLUS.DOC"
  905.                        |       |             |       |
  906.                       0x00    EST         7:18 PM   0x09
  907.      
  908.      
  909.       D. B Plus Control Sequences.
  910.      
  911.          The B Plus Protocol defines several Control Sequences in
  912.          addition to packets.  Control Sequences are used to manage
  913.          the progress of the B Plus Session.
  914.      
  915.          1. Enquire.
  916.      
  917.             The Enquire Control Sequence consists of the single
  918.             character:
  919.      
  920.                     <ENQ>
  921.                      0x10
  922.      
  923.             It is sent in one of two circumstances:
  924.      
  925.                  o  The Responder is in terminal mode and the Initiator
  926.                     wants to synchronize its <Sequence> number, and to
  927.                     tell the Responder to set up for normal B Protocol.
  928.                     When the <ENQ> is received, the Responder must:
  929.      
  930.                       >  Prepare for 512 byte data blocks
  931.                       >  Prepare for Standard Checksum
  932.                       >  Initialize its Sequence to 0x30
  933.                       >  Transmit the string:
  934.      
  935.                            <DLE> + + <DLE> 0x30
  936.      
  937.                       >  Return to terminal mode.  Note:  The terminal
  938.                          program  definately should NOT enter B Protocol
  939.                          mode when the <ENQ> is received.
  940.      
  941.                  o  The entity sending the packet has received a
  942.                     Negative Acknowledge, or timed out while waiting for
  943.                     an Acknowledge.  The response to an <ENQ> during a B
  944.                     Plus session is a Positive Acknowledge.
  945.      
  946.          2. Positive Acknowledge.
  947.      
  948.             When a correctly checked and sequenced packet is received,
  949.             a Positive Acknowledge is transmitted.  This consists of:
  950.      
  951.                  <DLE> Sequence
  952.      
  953.             where Sequence is the Sequence number of the last validly
  954.             received packet.
  955.  
  956.                                         16
  957.  
  958.  
  959.  
  960.      
  961.          3. Wait.
  962.      
  963.             The Wait Control Sequence informs the receiving entity that
  964.             the sending entity requires additional time to process what
  965.             it has received.  Wait is sent as:
  966.      
  967.                 <DLE> ;
  968.      
  969.      
  970.          4. Negative Acknowledge.
  971.      
  972.             When the receiving entity receives a packet with an
  973.             unexpected <Sequence>, improper checksum or times out, it
  974.             sends a Negative Acknowledge to the other entity.  This
  975.             consists of the single byte:
  976.      
  977.                  <NAK>  0x15
  978.      
  979.             When the sending entity receives a NAK, it initiates a
  980.             Resynchronization Process by sending two <ENQ> characters
  981.             and waiting until it receives two identical Positive
  982.             Acknowlegements.
  983.      
  984.          5. Panic Abort.
  985.      
  986.             The B Plus Protocol recognizes a series of four <DLE>
  987.             characters as a panic abort.  The need for such a facility
  988.             can arise if the Responder computer becomes locked up during
  989.             a transfer, and it is necessary to reboot.  Since <DLE> is
  990.             really control-P, sending it is a very simple procedure.
  991.      
  992.             In addition, the Initiator recognizes the seqeunce:
  993.      
  994.                  <DLE> +
  995.      
  996.             while waiting for a Positive Acknowledge as being incorrect,
  997.             and will abort the transfer.  This can happen as above, but
  998.             before the operator can press control-P the Initiator sends
  999.             an <ENQ> during a down-load to find out what is happening.
  1000.             The Responder, now in terminal emulation mode, responds
  1001.             with:
  1002.      
  1003.                  <DLE> + + <DLE> 0
  1004.      
  1005.             and the Initiator will abort cleanly.  For this reason it is
  1006.             essential that any B Plus implementation observe the rules
  1007.             for <ENQ>:  If in terminal mode, send <DLE> + + <DLE> 0;
  1008.             otherwise send <DLE> Sequence.
  1009.      
  1010.  
  1011.  
  1012.  
  1013.  
  1014.  
  1015.                                         17
  1016.  
  1017.  
  1018.  
  1019.       E. Negotiation of Transport Parameters.
  1020.      
  1021.          The Initiator begins a B Plus protocol session by sending:
  1022.      
  1023.                    <ENQ>
  1024.      
  1025.          while the Responder is in terminal mode.  The Responder sets
  1026.          itself up for:
  1027.      
  1028.              o  Standard Checksum
  1029.              o  Default Quoting
  1030.              o  512 byte data block
  1031.              o  Sets its Sequence to 0x30 (`0')
  1032.              o  transmits the sequence:
  1033.      
  1034.                        <DLE> + + <DLE> 0
  1035.      
  1036.              o  returns to terminal mode.
  1037.      
  1038.          The Initiator, detecting the `<DLE> + +', sends a Transport
  1039.          Parameters Packet using Standard Checksum and quoting of
  1040.          0x00 thru 0x1f and 0x80 thru 0x9f.  When the Responder
  1041.          properly receives this packet, it must transmit a Transport
  1042.          Parameters Packet indicating its own parameter settings.
  1043.          Once the Initiator Acknowledges the Responder`s Transport
  1044.          Parameters Packet, each entity then establishes its
  1045.          operating configuration based on the minimal matching
  1046.          parameters.  In particular, the Initiator and Responder each
  1047.          choose the minimum of:
  1048.      
  1049.             Own       Other's
  1050.          Parameter   Parameter
  1051.      
  1052.             WS           WR    <- Note the cross-comparison of
  1053.             WR           WS    <- these parameters.
  1054.             BS           BS
  1055.             CM           CM
  1056.             TL           TL
  1057.             DR           DR
  1058.             UR           UR
  1059.             FI           FI
  1060.      
  1061.          and the inclusive-or of the Quoting Sets.
  1062.      
  1063.          For example, if the Initiator sends the sequence:
  1064.      
  1065.                   0x01 0x01 0x08 0x01 0x01 0x00
  1066.                   0x14 0xd4 0x00 0x00          <- Quoting Set
  1067.                   0x00 0x00 0x00 0x00          <-
  1068.                   0x01 0x00 0x00               <- DR UR FI
  1069.      
  1070.          and the Responder returns:
  1071.      
  1072.                   0x00 0x01 0x04 0x00 0x01 0x00
  1073.  
  1074.                                         18
  1075.  
  1076.  
  1077.  
  1078.                   0x54 0xd4 0x00 0x00          <- Quoting Set
  1079.                   0x40 0x50 0x00 0x00          <-
  1080.      
  1081.          The following parameters are used by both entities:
  1082.      
  1083.             Parameter  Initiator  Responder
  1084.                WS         0x01      0x00      Initiator sends 1
  1085.                                               packet ahead.
  1086.      
  1087.                WR         0x00      0x01      Responder sends 1
  1088.                                               packet and waits for
  1089.                                               Postive Acknowledge
  1090.                BS         0x04      0x04      Both use 512 byte
  1091.                                               data body
  1092.                CM         0x00      0x00      Standard Checksum
  1093.      
  1094.                The following characters will be quoted when
  1095.                transmitted by either entity:
  1096.      
  1097.                   0x01 0x03 0x05 0x10 0x11 0x13 0x15 0x81 0x91 0x93
  1098.                   SOH  ETX  ENQ  DLE  XON  XOFF NAK  SOH  XON  XOFF
  1099.      
  1100.                This would be the quoting used for a Responder
  1101.                having a modem which treats the 0x01 as "Escape to
  1102.                command mode" and in addition responds to flow
  1103.                control characters (0x11 0x13 0x91 0x93).
  1104.      
  1105.          Since the Responder did not transmit the DR, UR, and FI
  1106.          parameters, the initiator sets them to 0x00.
  1107.      
  1108.          The next packet transmitted will be expected to obey the
  1109.          negotiated Transport Parameters.
  1110.              
  1111.  
  1112.  
  1113.  
  1114.  
  1115.  
  1116.  
  1117.  
  1118.  
  1119.  
  1120.  
  1121.  
  1122.  
  1123.  
  1124.  
  1125.  
  1126.  
  1127.  
  1128.  
  1129.  
  1130.  
  1131.  
  1132.  
  1133.                                         19
  1134.  
  1135.  
  1136.  
  1137.       F. Terminal Program States.
  1138.      
  1139.          This section describes the expected state transitions for a
  1140.          terminal program which supports the B Plus Protocol.
  1141.      
  1142.          Current State      Event     Action         Next State
  1143.          ------------------------------------------------------------
  1144.          Terminal      <ENQ> Rcvd.    Return:        Terminal
  1145.                                   <DLE> + + <DLE> 0
  1146.                                   Set up for normal
  1147.                                   B Protocol
  1148.      
  1149.                        <DLE> Rcvd.    None.          DLE_Seen
  1150.      
  1151.                        <Other>        Process as an
  1152.                                       ASCII char.    Terminal
  1153.      
  1154.          ------------------------------------------------------------
  1155.          DLE_Seen      <B> Rcvd.      None.          Get_First_Packet
  1156.      
  1157.                        <other> Rcvd.  None.          Terminal
  1158.      
  1159.          ------------------------------------------------------------
  1160.          Get_First_Packet        Receive the Packet
  1161.                        Valid packet :
  1162.      
  1163.                        <+>      Process Transport     Terminal
  1164.                                  Parameters; set
  1165.                                  up for B Plus if
  1166.                                  successful exchange
  1167.      
  1168.                        <T>      Invoke Transfer       Terminal
  1169.                                  Process
  1170.      
  1171.                        <other>  Return Failure        Terminal
  1172.                                  Packet N
  1173.      
  1174.          ------------------------------------------------------------
  1175.      
  1176.  
  1177.  
  1178.  
  1179.  
  1180.  
  1181.  
  1182.  
  1183.  
  1184.  
  1185.  
  1186.  
  1187.  
  1188.  
  1189.  
  1190.  
  1191.  
  1192.                                         20
  1193.  
  1194.  
  1195.  
  1196.       G. Wait for Acknowledge.
  1197.      
  1198.          The Wait for Acknowledge procedure is the work-horse of the
  1199.          B+ Protocol.  It is implemented as a Finite State Automaton
  1200.          having thirteen states as follows:
  1201.      
  1202.            State               Description
  1203.          ----------------   ----------------------------------------
  1204.          S_Get_DLE          Wait for <DLE> from Responder.
  1205.          S_DLE_Seen         Get character following the <DLE>.
  1206.          S_DLE_B_Seen       Receive Packet Sequence Number.
  1207.          S_Get_Data         Receive data portion of packet.
  1208.          S_Get_Check        Receive check value.
  1209.          S_Get_CRC          Receive CRC-16.
  1210.          S_Verify_CRC       Compare received to calculated CRC-16.
  1211.          S_Verify_CKS       Compare received to calculated checksum.
  1212.          S_Verify_Packet    Check for failure packet; verify packet
  1213.                             sequence number.
  1214.          S_Send_NAK         Count error; send <NAK> to Responder.
  1215.          S_Send_ACK         Send ACK sequence to Responder.
  1216.          S_Send_ENQs        Count error; Send two <ENQ> characters to
  1217.                             Responder.
  1218.          S_Resend_Packets   Retransmit packet(s) to Responder.
  1219.      
  1220.      
  1221.          The State Transition table follows:
  1222.      
  1223.          State              Event          Action              Next State
  1224.          ----------------   ------------   -----------------   -----------
  1225.          S_Get_DLE          <DLE>           ...                S_DLE_Seen
  1226.                             <NAK>           ...                S_Send_ENQ
  1227.                             <ENQ>           ...                S_Send_ACK
  1228.                             <ETX>           ...                S_Send_NAK
  1229.                             timeout         ...                S_Send_ENQ
  1230.                             other           ...                S_Get_DLE
  1231.      
  1232.          S_DLE_Seen         <digit>        Release Packet      return success
  1233.                                                -or-
  1234.                                            If <ENQ> sent       S_Resend_Packets
  1235.                                            else                S_Get_DLE
  1236.                             <B>             ...                S_DLE_B_Seen
  1237.                             <;>             ...                S_Get_DLE
  1238.                             <ENQ>           ...                S_Send_ACK
  1239.                             timeout         ...                S_Send_ENQ
  1240.                             other           ...                S_Get_DLE
  1241.      
  1242.          S_DLE_B_Seen       <ENQ>           ...                S_Send_ACK
  1243.                             <char>         Save <char>
  1244.                                            Intit Check Value   S_Get_Data
  1245.                             timeout         ...                S_Send_NAK
  1246.      
  1247.  
  1248.  
  1249.  
  1250.  
  1251.                                         21
  1252.  
  1253.  
  1254.  
  1255.          S_Get_Data         <ETX>           ...                S_Get_Check
  1256.                             timeout         ...                S_Send_NAK
  1257.                             <ENQ>           ...                S_Send_ACK
  1258.                             <char>         Add <char> to
  1259.                                              check value
  1260.                                            Store <char> in
  1261.                                              buffer            S_Get_Data
  1262.      
  1263.          S_Get_Check        <char>         If Check Method is
  1264.                                              CRC_16            S_Get_CRC
  1265.                                              Checksum          S_Verify_CKS
  1266.                             timeout         ...                S_Send_NAK
  1267.      
  1268.          S_Get_CRC          <char>         Add <char> to
  1269.                                              Received CRC-16   S_Verify_CRC
  1270.                             timeout         ...                S_Send_NAK
  1271.      
  1272.          S_Verify_CRC        ...           If Received CRC-16
  1273.                                              = Calc. CRC-16    S_Verify_Packet
  1274.                                            else                S_Send_NAK
  1275.      
  1276.          S_Verify_CKS        ...           If Received CKS
  1277.                                              = Calc. CKS       S_Verify_Packet
  1278.                                            else                S_Send_NAK
  1279.      
  1280.          S_Verify_Packet    ...            If Saved <char>
  1281.                                              = expected Seq
  1282.                                                 number         Return size
  1283.                                               -or-
  1284.                                            If Packet Type
  1285.                                              = `F'             Return size
  1286.                                            If duplicate
  1287.                                              packet            S_Send_ACK
  1288.                                            else                S_Send_NAK  
  1289.      
  1290.          S_Send_NAK         ...            Count Receive
  1291.                                               Error
  1292.                                            If too many errors  Return failure
  1293.                                            If not Aborting
  1294.                                            then Send <NAK>
  1295.                                                                S_Get_DLE
  1296.      
  1297.          S_Send_ACK         ...            IF not Aborting
  1298.                                            then Send ACK sequence
  1299.                                                                S_Get_DLE
  1300.      
  1301.          S_Send_ENQ         ...            Send <ENQ><ENQ>     S_Get_DLE
  1302.      
  1303.          S_Resend_Packets   ...            Send all un-ACKed
  1304.                                              packets.          S_Get_DLE
  1305.      
  1306.          Note:  "Aborting" means that a Failure Packet has been sent.  If
  1307.                 Failure Packet has been sent, all outstanding packets are
  1308.                 assumed to be ACKed.
  1309.  
  1310.                                         22
  1311.  
  1312.  
  1313.  
  1314.       H. Packet Send Ahead
  1315.      
  1316.          One of the most useful features of the B Plus Protocol, from
  1317.          the user's point of view, is its ability to send more than
  1318.          one packet ahead of receiving the acknowledgment of the
  1319.          oldest one.  This improves thru-put by overlapping the I/O
  1320.          performed on both the Initiator and Responder computers,
  1321.          including the time required for the Responder computer's
  1322.          acknowledgement to arrive at the Initiator and wake up the
  1323.          Initiator's application program.
  1324.      
  1325.          The Packet Send Ahead is accomplished by keeping a set of
  1326.          buffers in memory, one for each permitted outstanding
  1327.          packet.  Each buffer contains the corresponding packet's
  1328.          <Sequence>, count, and the data itself.  In addition a
  1329.          counter of outstanding packets (ie, not yet ACKed) is
  1330.          maintained and incremented whenever a packet is sent for the
  1331.          first time.
  1332.      
  1333.          Two indicies into the set of buffers are used to keep track
  1334.          of the Send Ahead status.  One keeps track of which buffer
  1335.          holds the oldest packet and the other which buffer may be
  1336.          filled with new data.
  1337.      
  1338.          When a packet is about to be sent, the outstanding count is
  1339.          checked to see if the maximum number of outstanding packets
  1340.          has been reached.  If so, a routine (GetACK) is invoked
  1341.          which waits for the ACK to arrive for the oldest outstanding
  1342.          packet.  Several possibilities exist:
  1343.              o The oldest packet is ACKed.  In this case, move the
  1344.                Oldest Outstanding index to point to the next oldest
  1345.                packet and decrement the outstanding packet count.
  1346.              o Some other packet in the buffer pool has been ACKed.
  1347.                This implies an ACK has been missed.  Move the Oldest
  1348.                Outstanding index to point to the buffer following the
  1349.                received ACK, and decrement the Outstanding Count
  1350.                accoringly.
  1351.              o A NAK is received.  Retransmit all packets which are
  1352.                outstanding.
  1353.      
  1354.          If the Outstanding count is still at the maximum, stay in
  1355.          GetACK.
  1356.      
  1357.          Finally, a procedure is necessary which calls GetACK until
  1358.          either a failure occurs or the Outstanding count is zero.
  1359.      
  1360.  
  1361.  
  1362.  
  1363.  
  1364.  
  1365.  
  1366.  
  1367.  
  1368.  
  1369.                                         23
  1370.  
  1371.  
  1372.  
  1373.          The Send Ahead Process proceeds as follows:
  1374.                                                      Receiver's
  1375.          Packet   Sequence  Buffer    Outstanding    Response
  1376.            1        `1'       0           1            ...
  1377.            2        `2'       1           2            ...
  1378.            3  GetACK                                 ACK `1'
  1379.                     `3'       0           2            ...
  1380.            4  GetACK                                 ACK `2'
  1381.                     `4'       1           2            ...
  1382.            5  GetACK                                 ACK `3'
  1383.                     `5'       0           2            ...   (Last)
  1384.               GetACK                                 ACK `4'
  1385.                                           1            ...
  1386.               GetACK                                 ACK `5'
  1387.      
  1388.  
  1389.  
  1390.  
  1391.  
  1392.  
  1393.  
  1394.  
  1395.  
  1396.  
  1397.  
  1398.  
  1399.  
  1400.  
  1401.  
  1402.  
  1403.  
  1404.  
  1405.  
  1406.  
  1407.  
  1408.  
  1409.  
  1410.  
  1411.  
  1412.  
  1413.  
  1414.  
  1415.  
  1416.  
  1417.  
  1418.  
  1419.  
  1420.  
  1421.  
  1422.  
  1423.  
  1424.  
  1425.  
  1426.  
  1427.  
  1428.                                         24
  1429.  
  1430.  
  1431.  
  1432.       I. Implementation Considerations
  1433.      
  1434.          1. Time-Out
  1435.      
  1436.             A per-character time-out of ten seconds should be used.
  1437.             Using anything less can result in a loss of good control
  1438.             over the exchange of packet and control sequences.  If
  1439.             conditions over a switched network degrade sufficiently, a
  1440.             small time out can lead to excessive retransmissions of
  1441.             data.  On the other hand, longer time-out values will result
  1442.             in a more sluggish detection of protocol breakdown.
  1443.      
  1444.             The receiving entity should be silent when a timeout occurs.
  1445.             That is, a <NAK> should not be sent when a timeout occurs
  1446.             while receiving a packet.  The reason is that under severely
  1447.             degraded network loading it may happen that it takes longer
  1448.             for the sending entity's data to arrive than the receiving
  1449.             entity's timeout interval.  This can lead to many kinds of
  1450.             situations in which there is excessive retransmission of
  1451.             data.  The question to be answered by the implementor is:
  1452.             "Am I more concerned about how fast I can shut down the
  1453.             transfer when the sending entity goes away than I am about
  1454.             getting the transfer to occur regardless of how long it
  1455.             takes?"  If the answer is that response to a vanished sender
  1456.             is more important, then send a <NAK> when a timeout occurs.
  1457.             If getting the job done is more important, then don't send
  1458.             the <NAK> on timeout.
  1459.      
  1460.          2. Packet Size.
  1461.      
  1462.             The following chart shows the percentage of houskeeping overhead
  1463.             for various packet sizes (not including quoted characters):
  1464.      
  1465.                                                       Packet
  1466.                Data  Packet                      Transmission Time
  1467.                Size   Size    Useful    Overhead   300 1200 2400
  1468.                ----  ------   ------    --------  ---- ---- ----
  1469.                128    135     94.8 %    5.2 %      4.5  1.1  0.6
  1470.                256    263     97.3 %    2.7 %      8.8  2.2  1.1
  1471.                384    391     97.7 %    2.3 %     13.0  3.3  1.6
  1472.                512    519     98.7 %    1.3 %     17.3  4.3  2.2
  1473.                640    647     98.9 %    1.1 %     21.6  5.4  2,7
  1474.                768    775     99.1 %    0.9 %     25.8  6.5  3,2
  1475.                896    903     99.2 %    0.8 %     30.1  7.5  3.8
  1476.               1024   1031     99.3 %    0.7 %     34.4  8.6  4.3
  1477.      
  1478.             At first glance it might seem reasonable to always use 1024 byte
  1479.             data packets.  However, consideration should be given to the
  1480.             amount of time required to recover from a transmission error.
  1481.             For example, using 1024 byte data packets at 300 baud, over a
  1482.             minute of excessive transmission time would result (two packets)
  1483.             each time an error occured.  Experience shows that keeping the
  1484.             packet transmission time to between four and five seconds
  1485.             results in a reasonably comfortable recovery time.  So, for best
  1486.  
  1487.                                         25
  1488.  
  1489.  
  1490.  
  1491.             over-all performance, the following packet sizes are
  1492.             recommended:
  1493.      
  1494.                Baud      Size
  1495.                ----      ----
  1496.                 300       128
  1497.                1200       512
  1498.                2400      1024
  1499.      
  1500.          3. Controlling Excessive Retransmissions.
  1501.      
  1502.             Over a very noisy link the send-ahead nature of B Plus might
  1503.             cause the performance to degrade due to retransmission of
  1504.             packets.  To circumvent this degradation, the following
  1505.             heuristic is recommended:
  1506.      
  1507.                Initialize  SA_Error_Count to zero.
  1508.                If packets are retransmitted, increment SA_Error_Count by 3.
  1509.                If SA_Error_Count is greater than or equal to 12, drop out of
  1510.                     Send-Ahead mode (ie, revert to send and wait mode).
  1511.                When a packet is ACKed, and SA_Error_Count is greater than
  1512.                     zero,  decrement SA_Error_Count by one.
  1513.      
  1514.             The values (increment by 3, limit of 12, decrement by 1) can be
  1515.             varied in accord with the implementor's experience, perhaps
  1516.             being established by user-definable parameters.
  1517.      
  1518.      
  1519.  
  1520.  
  1521.  
  1522.  
  1523.  
  1524.  
  1525.  
  1526.  
  1527.  
  1528.  
  1529.  
  1530.  
  1531.  
  1532.  
  1533.  
  1534.  
  1535.  
  1536.  
  1537.  
  1538.  
  1539.  
  1540.  
  1541.  
  1542.  
  1543.  
  1544.  
  1545.  
  1546.                                         26
  1547.  
  1548.  
  1549.  
  1550.       J. B Plus Transport Layer.
  1551.      
  1552.          Some distributed applications (that is, applications in
  1553.          which the Initiator and Responder each perform some of the
  1554.          work) require that blocks of information be exchanged.
  1555.          Running such applications over normal communication channels
  1556.          can cause loss or altering of data, yielding unpredictable
  1557.          results.  To aleviate this possibility, the B Plus Protocol
  1558.          provides the ability to use the underlying packet structure
  1559.          to exchange blocks of data with error detection and
  1560.          retransmission.
  1561.      
  1562.          Entering the Transport Layer operation is more complicated
  1563.          than the File Transfer mode previously described:
  1564.      
  1565.              o  The user invokes a CompuServe application
  1566.              o  The application program transmits a CompuServe
  1567.                 Application Protocol escape sequence.
  1568.              o  The user's terminal program responds with an escape
  1569.                 sequence which informs the host application that it
  1570.                 must use the Transport Layer.
  1571.              o  The host program initializes its B Plus routines,
  1572.                 setting the Transport Layer parameter to 0x01.
  1573.              o  The terminal program waits until its own B Plus     
  1574.                 routines have been initialized, also setting the     
  1575.                 Transport Layer parameter to 0x01.
  1576.              o  Once the host and remote B Plus routines have     
  1577.                 exchanged their Transport Layer Parameters, the
  1578.                 Transport Layer is in effect.  The succeeding action
  1579.                 is a function of the application.
  1580.      
  1581.          From an implementation standpoint, the primary differences
  1582.          from the B Plus Protocol so far described are:
  1583.      
  1584.              o  Separate Packet Sequence Numbers are maintained for
  1585.                 sending and receiving.
  1586.              o  Received Packets are placed in a first-in-first-out
  1587.                 queue.
  1588.              o  Another level of software is placed between the     
  1589.                 packet handlers and the application.  This level is
  1590.                 responsible for sending and receiving blocks of data,
  1591.                 packaging them into protocol-sized packets.
  1592.      
  1593.          The following Packet Types are used in the Transport Layer:
  1594.      
  1595.              `M':  This is a data packet; another data packet follows.
  1596.      
  1597.              `L':  This is the last data packet for the current block.
  1598.      
  1599.          A Failure Packet will terminate the transport layer for both
  1600.          entities.
  1601.      
  1602.  
  1603.  
  1604.  
  1605.                                         27
  1606.  
  1607.  
  1608.  
  1609.       K. Initiation of a B Plus Session.
  1610.      
  1611.          The following state machine describes the process of a host
  1612.          entity initiating a B Plus Session.  Its starting state is
  1613.          Send_ENQ.
  1614.      
  1615.          State         Received  Action                   Next State
  1616.          ------        --------  ----------------------   ----------
  1617.          Send_ENQ        ...     Transmit <ENQ>
  1618.                                  Set Standard Checksum
  1619.                                  Set 512 byte Data Block
  1620.                                  Set default quote set
  1621.                                  Clear Plus_Seen and
  1622.                                  Plus_Plus flags          Get_DLE
  1623.          -----------------------------------------------------------
  1624.          Get_DLE       <DLE>     ...                      Get_Digit
  1625.                        <+>       If Plus_Seen true,
  1626.                                    then set Plus_Plus
  1627.                                         ...               Get_DLE
  1628.                        timeout                            Send_ENQ
  1629.          ------------------------------------------------------------
  1630.          Get_Digit     <digit>   Initialize Send and
  1631.                                    Receive Sequence
  1632.                                    Numbers                Send_Parameters
  1633.                        <+>       Set Plus_Seen            Get_DLE
  1634.                        timeout       ...                  Send_ENQ   
  1635.          ------------------------------------------------------------
  1636.          Send_Parameters ...     If Plus_Seen true,
  1637.                                    then
  1638.                                       if Plus_Plus true,
  1639.                                         then set to quote
  1640.                                            0x00-0x1f and
  1641.                                            0x80-0x9f
  1642.                                       Send Parameters Packet
  1643.                                       Receive Parameters Packet
  1644.                                       Establish session's parameters
  1645.                                                            
  1646.                                                           Exit
  1647.          -------------------------------------------------------------
  1648.      
  1649.      
  1650.  
  1651.  
  1652.  
  1653.  
  1654.  
  1655.  
  1656.  
  1657.  
  1658.  
  1659.  
  1660.  
  1661.  
  1662.  
  1663.  
  1664.                                         28
  1665.  
  1666.  
  1667.  
  1668.       L. Supporting the Various B Protocol Versions
  1669.      
  1670.          There are three versions of B Protocl which an implementor must
  1671.          be aware of.  Any new implementation should follow the B Plus
  1672.          Protocol as described in this document to ensure full
  1673.          compatibility with all existing CompuServe Host software.  The
  1674.          three versions are:
  1675.      
  1676.                   o  "Classic" B Protocol
  1677.                   o  An interim version of B Plus (called Quick B)
  1678.                   o  B Plus as described in this document
  1679.      
  1680.          The differences are:
  1681.      
  1682.              Initial <ENQ> response:
  1683.                   Classic B:      <DLE> digit
  1684.                   QuickB:         <DLE> + <DLE> digit
  1685.                   B Plus:         <DLE> + + <DLE> digit
  1686.      
  1687.              Default Quoting Sets:
  1688.                   Classic B:      0x00 -> 0x1f
  1689.                   QuickB:         0x00 0x03 0x05 0x10 0x11 0x13 0x15
  1690.                   B Plus:         0x03 0x05 0x10 0x11 0x13 0x15
  1691.      
  1692.              Extended Quoting:
  1693.                   Classic B:      none
  1694.                   QuickB:         Specified by the DQ Parameter:
  1695.                                   0x00 : 0x00 0x03 0x05 0x10 0x11 0x13 0x15
  1696.                                   0x01 : 0x03 0x05 0x10 0x11 0x13 0x15
  1697.                                   0x02 : 0s03 0x05 0x10 0x11 0x13 0x15 0x91 0x93
  1698.                                   0x03 : 0x00-0x1f and 0x80-0x9f
  1699.                   B Plus:         Established by the Q1 thru Q8 parameters.
  1700.                                   (Ignore R0)
  1701.      
  1702.              Quoting of the Paramters Packet:
  1703.                   Classic B:      No paramaters packet
  1704.                   QuickB:         0x00 -> 0x1f
  1705.                   B Plus:         0x00 -> 0x1f and 0x80 -> 0x9f
  1706.      
  1707.              Response to a <NAK>:
  1708.                   Classic B:      Retransmit the last packet
  1709.                   QuickB:         Resynchronize with <ENQ><ENQ>, wait for
  1710.                                   two identical ACK sequences, retransmit
  1711.                                   as necessary.
  1712.                   B Plus:         Same as QuickB.
  1713.      
  1714.  
  1715.  
  1716.  
  1717.  
  1718.  
  1719.  
  1720.  
  1721.  
  1722.  
  1723.                                         29
  1724.  
  1725.  
  1726.  
  1727.          CompuServe Host software will support all three B Protocol
  1728.          versions.  In order to do so, it relies on the initial response
  1729.          to <ENQ> to determine what version is being used in the terminal
  1730.          software.  The defaults given in Section D.1 ("Enquire") are
  1731.          intended to reflect "Classic" B Protocol.  If the Host receives
  1732.              
  1733.              <DLE> <+> <DLE> <digit>
  1734.      
  1735.          it sends its Transport Parameters Packet using "Classic" B data
  1736.          quoting (0x00 -> 0x1f).  If two "+" chracters are received, it
  1737.          will quote 0x00 -> 0x1f and 0x80 -> 0x9f.  This is done to
  1738.          maximize the chances of getting the packet through most modems
  1739.          and networks.  Once the Transport Parameters Packets have been
  1740.          successuflly exchanged, the Host software uses the negotiated
  1741.          quoting set, and the remote is expected to do likewise.
  1742.      
  1743.          Negotiation of quoted characters allows implementors to provide
  1744.          configuration set up to cope with a wide variety of modems,
  1745.          oeprating system, network, and other situations which can
  1746.          adversely affect thr transmission of 8-bit binary data.
  1747.      
  1748.      
  1749.  
  1750.  
  1751.  
  1752.  
  1753.  
  1754.  
  1755.  
  1756.  
  1757.  
  1758.  
  1759.  
  1760.  
  1761.  
  1762.  
  1763.  
  1764.  
  1765.  
  1766.  
  1767.  
  1768.  
  1769.  
  1770.  
  1771.  
  1772.  
  1773.  
  1774.  
  1775.  
  1776.  
  1777.  
  1778.  
  1779.  
  1780.  
  1781.  
  1782.                                         30
  1783.  
  1784.  
  1785.  
  1786.       M. Check Value Calculation.
  1787.      
  1788.          1. Standard B Protocol Checksum.
  1789.      
  1790.             The following C-language code fragment illustrates the
  1791.             Standard Checksum calculation:
  1792.      
  1793.             int
  1794.               checksum;
  1795.      
  1796.             do_checksum (ch)
  1797.             unsigned int ch;
  1798.             {
  1799.                 checksum = checksum << 1;
  1800.      
  1801.                 if checksum > 0xff
  1802.                     checksum = (checksum  & 0xff) + 1;
  1803.      
  1804.                 checksum += ch & 0xff;
  1805.      
  1806.                 if checksum > 0xff
  1807.                     checksum = (checksum & 0xff) + 1;
  1808.             };
  1809.      
  1810.  
  1811.  
  1812.  
  1813.  
  1814.  
  1815.  
  1816.  
  1817.  
  1818.  
  1819.  
  1820.  
  1821.  
  1822.  
  1823.  
  1824.  
  1825.  
  1826.  
  1827.  
  1828.  
  1829.  
  1830.  
  1831.  
  1832.  
  1833.  
  1834.  
  1835.  
  1836.  
  1837.  
  1838.  
  1839.  
  1840.  
  1841.                                         31
  1842.  
  1843.  
  1844.  
  1845.          2. XMODEM-Style CRC-16.
  1846.      
  1847.             /*
  1848.              * Calculates XMODEM-style CRC (uses the CCITT V.41
  1849.              * polynomial but
  1850.              * completely backwards from the normal bit ordering).
  1851.              */
  1852.             static unsigned crc_xmodem_tab[] = {
  1853.             0x0000,0x1021,0x2042,0x3063,0x4084,0x50A5,0x60C6,0x70E7,
  1854.             0x8108,0x9129,0xA14A,0xB16B,0xC18C,0xD1AD,0xE1CE,0xF1EF,
  1855.             0x1231,0x0210,0x3273,0x2252,0x52B5,0x4294,0x72F7,0x62D6,
  1856.             0x9339,0x8318,0xB37B,0xA35A,0xD3BD,0xC39C,0xF3FF,0xE3DE,
  1857.             0x2462,0x3443,0x0420,0x1401,0x64E6,0x74C7,0x44A4,0x5485,
  1858.             0xA56A,0xB54B,0x8528,0x9509,0xE5EE,0xF5CF,0xC5AC,0xD58D,
  1859.             0x3653,0x2672,0x1611,0x0630,0x76D7,0x66F6,0x5695,0x46B4,
  1860.             0xB75B,0xA77A,0x9719,0x8738,0xF7DF,0xE7FE,0xD79D,0xC7BC,
  1861.             0x48C4,0x58E5,0x6886,0x78A7,0x0840,0x1861,0x2802,0x3823,
  1862.             0xC9CC,0xD9ED,0xE98E,0xF9AF,0x8948,0x9969,0xA90A,0xB92B,
  1863.             0x5AF5,0x4AD4,0x7AB7,0x6A96,0x1A71,0x0A50,0x3A33,0x2A12,
  1864.             0xDBFD,0xCBDC,0xFBBF,0xEB9E,0x9B79,0x8B58,0xBB3B,0xAB1A,
  1865.             0x6CA6,0x7C87,0x4CE4,0x5CC5,0x2C22,0x3C03,0x0C60,0x1C41,
  1866.             0xEDAE,0xFD8F,0xCDEC,0xDDCD,0xAD2A,0xBD0B,0x8D68,0x9D49,
  1867.             0x7E97,0x6EB6,0x5ED5,0x4EF4,0x3E13,0x2E32,0x1E51,0x0E70,
  1868.             0xFF9F,0xEFBE,0xDFDD,0xCFFC,0xBF1B,0xAF3A,0x9F59,0x8F78,
  1869.             0x9188,0x81A9,0xB1CA,0xA1EB,0xD10C,0xC12D,0xF14E,0xE16F,
  1870.             0x1080,0x00A1,0x30C2,0x20E3,0x5004,0x4025,0x7046,0x6067,
  1871.             0x83B9,0x9398,0xA3FB,0xB3DA,0xC33D,0xD31C,0xE37F,0xF35E,
  1872.             0x02B1,0x1290,0x22F3,0x32D2,0x4235,0x5214,0x6277,0x7256,
  1873.             0xB5EA,0xA5CB,0x95A8,0x8589,0xF56E,0xE54F,0xD52C,0xC50D,
  1874.             0x34E2,0x24C3,0x14A0,0x0481,0x7466,0x6447,0x5424,0x4405,
  1875.             0xA7DB,0xB7FA,0x8799,0x97B8,0xE75F,0xF77E,0xC71D,0xD73C,
  1876.             0x26D3,0x36F2,0x0691,0x16B0,0x6657,0x7676,0x4615,0x5634,
  1877.             0xD94C,0xC96D,0xF90E,0xE92F,0x99C8,0x89E9,0xB98A,0xA9AB,
  1878.             0x5844,0x4865,0x7806,0x6827,0x18C0,0x08E1,0x3882,0x28A3,
  1879.             0xCB7D,0xDB5C,0xEB3F,0xFB1E,0x8BF9,0x9BD8,0xABBB,0xBB9A,
  1880.             0x4A75,0x5A54,0x6A37,0x7A16,0x0AF1,0x1AD0,0x2AB3,0x3A92,
  1881.             0xFD2E,0xED0F,0xDD6C,0xCD4D,0xBDAA,0xAD8B,0x9DE8,0x8DC9,
  1882.             0x7C26,0x6C07,0x5C64,0x4C45,0x3CA2,0x2C83,0x1CE0,0x0CC1,
  1883.             0xEF1F,0xFF3E,0xCF5D,0xDF7C,0xAF9B,0xBFBA,0x8FD9,0x9FF8,
  1884.             0x6E17,0x7E36,0x4E55,0x5E74,0x2E93,0x3EB2,0x0ED1,0x1EF0};
  1885.      
  1886.             unsigned CRC;
  1887.             UpdCrc (Byte)
  1888.             unsigned int ByteC;
  1889.             {  CRC =
  1890.                  crc_xmodem_tab [(CRC >> 8 ^ Byte) & 0xff] ^ (crc << 8);
  1891.             };
  1892.      
  1893.  
  1894.  
  1895.  
  1896.  
  1897.  
  1898.  
  1899.  
  1900.                                         32
  1901.  
  1902.  
  1903.  
  1904.       N. Interrogation.
  1905.      
  1906.          Although not part of the B Plus Protocol, implementors are urged
  1907.          to support the CompuServe Interrogation Sequence.  This process
  1908.          passes information to the CompuServe Host to identify the
  1909.          various options supported by the terminal program.  Host
  1910.          software will generally perform an Enquire (Section D.1) first
  1911.          to determine if the terminal program supports B Protocol.  If B
  1912.          Protocl ("Classic," QuickB, or B Plus) is supported, the host
  1913.          then sends the sequence:
  1914.      
  1915.                   <ESC> I
  1916.      
  1917.          When the terminal program receives this sequence of characters,
  1918.          it transmits an Interrogation Response as follows:
  1919.      
  1920.              <#> <Mod> <Ver> <F-codes> <+> <Check> <CR>
  1921.      
  1922.          where:
  1923.      
  1924.              <#>          Identifies the string as an Interrogation
  1925.                           Response
  1926.      
  1927.              <Mod>        Specifies the specific hardware or operating
  1928.                           system, or a generic class of software.  It is
  1929.                           always three characters in length.  In addition
  1930.                           to several reserved codes, the following
  1931.                           generic codes are defined:
  1932.                                 APX - Apple (TM) II/Macintosh
  1933.                                 ATX - Atari (TM) 8, 16, and 32 bit
  1934.                                 AUT - Auto-Script Program
  1935.                                 CCX - Commodore (TM) C64 and Amiga
  1936.                                 CPM - CP/M (TM) Operating System
  1937.                                 IBX - IBM (TM) Compatible
  1938.                                 XXX - Other model/type
  1939.      
  1940.              <Ver>        Gives the terminal software version number.  It
  1941.                           may contain Letters, Digits, and Periods.
  1942.      
  1943.              <F-codes>    A series of character fields giving the
  1944.                           options supported.  Each <F-code> is followed
  1945.                           by a comma.  The currently recognized <F-codes>
  1946.                           are as follows:
  1947.      
  1948.                             Cursor/Screen Control
  1949.                                  AC : ANSI Color
  1950.                                  CA : ANSI/VT100 Cursor Control
  1951.                                  CC : VIDTEX/VT52 Cursor Control
  1952.                                  CW : Wide mode (Double width characters
  1953.                                            invoked by <ESC> <m>
  1954.                                            uninvoked by <ESC> <l> (lower
  1955.                                                 case L)
  1956.                                  SSyx : Screen Size; y gives number of
  1957.                                         lines + 31, x gives number of
  1958.  
  1959.                                         33
  1960.  
  1961.  
  1962.  
  1963.                                         columns plus 31.  SS7o identifies
  1964.                                         a 24 line by 80 column screen.
  1965.                                         It is suggested that the SS field
  1966.                                         always be present.
  1967.                             
  1968.                             Graphics
  1969.                                  GF : GIF graphics
  1970.                                  GH : High resolution RLE graphics
  1971.                                  GM : Medium resolution RLE graphics
  1972.                                  NF : Full NAPLPS graphics
  1973.      
  1974.                             Protocols
  1975.                                  AP : Recognizes and properly responds to
  1976.                                       the CompuServe Application Protocol
  1977.                                       escape sequences
  1978.                                  CB : Capture Buffer
  1979.                                  PB : B Protocol (includes QuickB and B
  1980.                                       Plus)
  1981.                                  PX : XMODEM
  1982.      
  1983.                             Miscellaneous
  1984.                                  HC : Hard Copy (printer connected)
  1985.                                  XX : Ignored
  1986.      
  1987.                        All other <F-codes> are reserved for future use.
  1988.      
  1989.              <Check>      This is a check value derived by adding
  1990.                           together all characters in the Interrogate
  1991.                           Response up to and including the +,
  1992.                           truncating the sum to 16 bits, and converting
  1993.                           it to an ASCII digit string.
  1994.      
  1995.              <CR>         This is the ASCII Carriage Return and serves to
  1996.                           terminate the Interrogate Response.
  1997.      
  1998.          If the <Check> value does not match, the host will send another
  1999.          <ESC> I and compare the string it receives to the previous one.
  2000.          If the two strings match, it is accepted, otherwise the <ESC> I
  2001.          and matching will continue for ten trials before giving up.
  2002.      
  2003.  
  2004.  
  2005.  
  2006.  
  2007.  
  2008.  
  2009.  
  2010.  
  2011.  
  2012.  
  2013.  
  2014.  
  2015.  
  2016.  
  2017.  
  2018.                                         34
  2019.  
  2020.  
  2021.  
  2022.          A sample Interrogate Response is:
  2023.      
  2024.              #IBX,CC,GH,GM,PB,+1035<CR>
  2025.      
  2026.          which specifies:
  2027.      
  2028.              o IBX : An IBM (TM) compatible system
  2029.              o CC  : Supports standard VIDTEX/VT52 cursor controls
  2030.              o GH  : Supports high-resolution RLE graphics
  2031.              o GM  : Supports medium-resulution RLE graphics
  2032.              o PB  : Supports B Protocol
  2033.              o 1035: Sum of "#IBM,CC,GH,GM,PB,+"
  2034.      
  2035.          For additional information concerning the Interrogation
  2036.          Response, please contact CompuServe Incorporated, Microcomputer
  2037.          Software Development.
  2038.      
  2039.  
  2040.  
  2041.  
  2042.  
  2043.  
  2044.  
  2045.  
  2046.  
  2047.  
  2048.  
  2049.  
  2050.  
  2051.  
  2052.  
  2053.  
  2054.  
  2055.  
  2056.  
  2057.  
  2058.  
  2059.  
  2060.  
  2061.  
  2062.  
  2063.  
  2064.  
  2065.  
  2066.  
  2067.  
  2068.  
  2069.  
  2070.  
  2071.  
  2072.  
  2073.  
  2074.  
  2075.  
  2076.  
  2077.                                         35
  2078.  
  2079.